package com.hieu.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.hieu.bean.Day;
import com.hieu.tripmanager.R;
import com.hieu.util.Util;

public class DayAdapter extends ArrayAdapter<Day> {

	Context context;
	int layoutResourceId;
	ArrayList<Day> mListDay;
	private Util util = new Util();

	public DayAdapter(Context context, int layoutResourceId, ArrayList<Day> data) {
		super(context, layoutResourceId, data);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.layoutResourceId = layoutResourceId;
		this.mListDay = data;
	}

	@Override
	public void add(Day object) {
		// TODO Auto-generated method stub
		super.add(object);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		DayHolder holder = null;

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new DayHolder();
			holder.day = (TextView) row.findViewById(R.id.txtDate);

			row.setTag(holder);
		} else {
			holder = (DayHolder) row.getTag();
		}

		Day day = mListDay.get(position);
		holder.day.setText(util.cutYear(day.getDay()));

		return row;
	}

	static class DayHolder {
		TextView day;
	}

}
